using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Risiko.State
{
  public class State
  {
    public Board board;
    public Deck deck;
    public PlayerList currentPlayer;
    public PlayerState[] playerStates;
    public GamePhase gamePhase;
    public GamePhase previousPhase;

    public List<String> Log;
    public int Round;

    static public Board GetClassicBoard()
    {
      Board board = new Board();
      board.continents = new Continent[6];

      // Europa = 0
      // Creazione continente
      Continent europe = new Continent() { name = "Europa", reinforcements = 5 };
      // Creazione territori
      Territory[] territories = new Territory[7];
      for (int i = 0; i < territories.Count(); ++i)
      {
        territories[i].territoryID = i;
        territories[i].hasOwner = false;
        territories[i].continentID = 0;
      }

      territories[0].name = "Gran Bretagna";
      territories[0].position = new Vector2(320, 150);
      territories[0].neighbors = new TerritoryReference[4];
      territories[0].neighbors[0] = new TerritoryReference() { continentID = 0, territoryID = 1 };
      territories[0].neighbors[1] = new TerritoryReference() { continentID = 0, territoryID = 3 };
      territories[0].neighbors[2] = new TerritoryReference() { continentID = 0, territoryID = 2 };
      territories[0].neighbors[3] = new TerritoryReference() { continentID = 0, territoryID = 6 };

      territories[1].name = "Islanda";
      territories[1].position = new Vector2(350, 77);
      territories[1].neighbors = new TerritoryReference[3];
      territories[1].neighbors[0] = new TerritoryReference() { continentID = 0, territoryID = 0 };
      territories[1].neighbors[1] = new TerritoryReference() { continentID = 0, territoryID = 3 };
      territories[1].neighbors[2] = new TerritoryReference() { continentID = 4, territoryID = 4 }; // Groenlandia

      territories[2].name = "Europa Settentrionale";
      territories[2].position = new Vector2(385, 173);
      territories[2].neighbors = new TerritoryReference[5];
      territories[2].neighbors[0] = new TerritoryReference() { continentID = 0, territoryID = 4 };
      territories[2].neighbors[1] = new TerritoryReference() { continentID = 0, territoryID = 0 };
      territories[2].neighbors[2] = new TerritoryReference() { continentID = 0, territoryID = 3 };
      territories[2].neighbors[3] = new TerritoryReference() { continentID = 0, territoryID = 5 };
      territories[2].neighbors[4] = new TerritoryReference() { continentID = 0, territoryID = 6 };

      territories[3].name = "Scandinavia";
      territories[3].position = new Vector2(390, 110);
      territories[3].neighbors = new TerritoryReference[4];
      territories[3].neighbors[0] = new TerritoryReference() { continentID = 0, territoryID = 0 };
      territories[3].neighbors[1] = new TerritoryReference() { continentID = 0, territoryID = 1 };
      territories[3].neighbors[2] = new TerritoryReference() { continentID = 0, territoryID = 2 };
      territories[3].neighbors[3] = new TerritoryReference() { continentID = 0, territoryID = 5 };

      territories[4].name = "Europa Meridionale";
      territories[4].position = new Vector2(383, 223);
      territories[4].neighbors = new TerritoryReference[6];
      territories[4].neighbors[0] = new TerritoryReference() { continentID = 1, territoryID = 2 }; // Egitto
      territories[4].neighbors[1] = new TerritoryReference() { continentID = 0, territoryID = 6 };
      territories[4].neighbors[2] = new TerritoryReference() { continentID = 0, territoryID = 2 };
      territories[4].neighbors[3] = new TerritoryReference() { continentID = 0, territoryID = 5 };
      territories[4].neighbors[4] = new TerritoryReference() { continentID = 1, territoryID = 4 }; // Africa del Nord
      territories[4].neighbors[5] = new TerritoryReference() { continentID = 2, territoryID = 6 }; // Medio Oriente


      territories[5].name = "Ucraina";
      territories[5].position = new Vector2(451, 155);
      territories[5].neighbors = new TerritoryReference[6];
      territories[5].neighbors[0] = new TerritoryReference() { continentID = 0, territoryID = 2 };
      territories[5].neighbors[1] = new TerritoryReference() { continentID = 0, territoryID = 3 };
      territories[5].neighbors[2] = new TerritoryReference() { continentID = 0, territoryID = 4 };
      territories[5].neighbors[3] = new TerritoryReference() { continentID = 2, territoryID = 0 }; // Afghanistan
      territories[5].neighbors[4] = new TerritoryReference() { continentID = 2, territoryID = 10 }; // Urali
      territories[5].neighbors[5] = new TerritoryReference() { continentID = 2, territoryID = 6 }; // Medio Oriente

      territories[6].name = "Europa Occidentale";
      territories[6].position = new Vector2(308, 204);
      territories[6].neighbors = new TerritoryReference[4];
      territories[6].neighbors[0] = new TerritoryReference() { continentID = 0, territoryID = 0 };
      territories[6].neighbors[1] = new TerritoryReference() { continentID = 0, territoryID = 2 };
      territories[6].neighbors[2] = new TerritoryReference() { continentID = 0, territoryID = 4 };
      territories[6].neighbors[3] = new TerritoryReference() { continentID = 1, territoryID = 4 }; // Africa del Nord

      europe.territories = territories;
      // Aggiunta in board e state
      board.continents[0] = europe;

      // Africa = 1
      // Creazione continente
      Continent africa = new Continent() { name = "Africa", reinforcements = 3 };
      // Creazione territori
      territories = new Territory[6];
      for (int i = 0; i < territories.Count(); ++i)
      {
        territories[i].territoryID = i;
        territories[i].hasOwner = false;
        territories[i].continentID = 1;
      }
      territories[0].name = "Congo";
      territories[0].position = new Vector2(380, 367);
      territories[0].neighbors = new TerritoryReference[3];
      territories[0].neighbors[0] = new TerritoryReference() { continentID = 1, territoryID = 1 };
      territories[0].neighbors[1] = new TerritoryReference() { continentID = 1, territoryID = 4 };
      territories[0].neighbors[2] = new TerritoryReference() { continentID = 1, territoryID = 5 };

      territories[1].name = "Africa Orientale";
      territories[1].position = new Vector2(447, 343);
      territories[1].neighbors = new TerritoryReference[6];
      territories[1].neighbors[0] = new TerritoryReference() { continentID = 1, territoryID = 0 };
      territories[1].neighbors[1] = new TerritoryReference() { continentID = 1, territoryID = 2 };
      territories[1].neighbors[2] = new TerritoryReference() { continentID = 1, territoryID = 3 };
      territories[1].neighbors[3] = new TerritoryReference() { continentID = 1, territoryID = 4 };
      territories[1].neighbors[4] = new TerritoryReference() { continentID = 1, territoryID = 5 };
      territories[1].neighbors[5] = new TerritoryReference() { continentID = 2, territoryID = 6 };

      territories[2].name = "Egitto";
      territories[2].position = new Vector2(401, 296);
      territories[2].neighbors = new TerritoryReference[4];
      territories[2].neighbors[0] = new TerritoryReference() { continentID = 1, territoryID = 1 };
      territories[2].neighbors[1] = new TerritoryReference() { continentID = 1, territoryID = 4 };
      territories[2].neighbors[2] = new TerritoryReference() { continentID = 0, territoryID = 4 }; // Europa Meridionale
      territories[2].neighbors[3] = new TerritoryReference() { continentID = 2, territoryID = 6 }; // Medio Oriente

      territories[3].name = "Madagascar";
      territories[3].position = new Vector2(467, 416);
      territories[3].neighbors = new TerritoryReference[2];
      territories[3].neighbors[0] = new TerritoryReference() { continentID = 1, territoryID = 1 };
      territories[3].neighbors[1] = new TerritoryReference() { continentID = 1, territoryID = 5 };

      territories[4].name = "Africa del Nord";
      territories[4].position = new Vector2(306, 290);
      territories[4].neighbors = new TerritoryReference[5];
      territories[4].neighbors[0] = new TerritoryReference() { continentID = 0, territoryID = 6 }; // Europa Occidentale
      territories[4].neighbors[1] = new TerritoryReference() { continentID = 1, territoryID = 0 };
      territories[4].neighbors[2] = new TerritoryReference() { continentID = 1, territoryID = 1 };
      territories[4].neighbors[3] = new TerritoryReference() { continentID = 1, territoryID = 2 };
      territories[4].neighbors[4] = new TerritoryReference() { continentID = 5, territoryID = 1 }; // Brasile

      territories[5].name = "Africa del Sud";
      territories[5].position = new Vector2(395, 415);
      territories[5].neighbors = new TerritoryReference[3];
      territories[5].neighbors[0] = new TerritoryReference() { continentID = 1, territoryID = 0 };
      territories[5].neighbors[1] = new TerritoryReference() { continentID = 1, territoryID = 3 };
      territories[5].neighbors[2] = new TerritoryReference() { continentID = 1, territoryID = 1 };

      africa.territories = territories;
      // Aggiunge il continente allo stato
      board.continents[1] = africa;


      // Asia = 2
      // Creazione continente
      Continent asia = new Continent() { name = "Asia", reinforcements = 7 };
      // Creazione territori
      territories = new Territory[12];
      for (int i = 0; i < territories.Count(); ++i)
      {
        territories[i].territoryID = i;
        territories[i].hasOwner = false;
        territories[i].continentID = 2;
      }
      territories[0].name = "Afghanistan";
      territories[0].position = new Vector2(528, 193);
      territories[0].neighbors = new TerritoryReference[4];
      territories[0].neighbors[0] = new TerritoryReference() { continentID = 2, territoryID = 1 };
      territories[0].neighbors[1] = new TerritoryReference() { continentID = 2, territoryID = 10 };
      territories[0].neighbors[2] = new TerritoryReference() { continentID = 2, territoryID = 6 };
      territories[0].neighbors[3] = new TerritoryReference() { continentID = 0, territoryID = 5 }; // Ucraina

      territories[1].name = "Cina";
      territories[1].position = new Vector2(638, 202);
      territories[1].neighbors = new TerritoryReference[7];
      territories[1].neighbors[0] = new TerritoryReference() { continentID = 2, territoryID = 0 };
      territories[1].neighbors[1] = new TerritoryReference() { continentID = 2, territoryID = 2 };
      territories[1].neighbors[2] = new TerritoryReference() { continentID = 2, territoryID = 6 };
      territories[1].neighbors[3] = new TerritoryReference() { continentID = 2, territoryID = 7 };
      territories[1].neighbors[4] = new TerritoryReference() { continentID = 2, territoryID = 8 };
      territories[1].neighbors[5] = new TerritoryReference() { continentID = 2, territoryID = 9 };
      territories[1].neighbors[6] = new TerritoryReference() { continentID = 2, territoryID = 10 };

      territories[2].name = "India";
      territories[2].position = new Vector2(588, 265);
      territories[2].neighbors = new TerritoryReference[3];
      territories[2].neighbors[0] = new TerritoryReference() { continentID = 2, territoryID = 1 };
      territories[2].neighbors[1] = new TerritoryReference() { continentID = 2, territoryID = 6 };
      territories[2].neighbors[2] = new TerritoryReference() { continentID = 2, territoryID = 8 };

      territories[3].name = "Cita";
      territories[3].position = new Vector2(591, 122);
      territories[3].neighbors = new TerritoryReference[4];
      territories[3].neighbors[0] = new TerritoryReference() { continentID = 2, territoryID = 9 };
      territories[3].neighbors[1] = new TerritoryReference() { continentID = 2, territoryID = 5 };
      territories[3].neighbors[0] = new TerritoryReference() { continentID = 2, territoryID = 11 };
      territories[3].neighbors[1] = new TerritoryReference() { continentID = 2, territoryID = 7 };

      territories[4].name = "Giappone";
      territories[4].position = new Vector2(726, 120);
      territories[4].neighbors = new TerritoryReference[2];
      territories[4].neighbors[0] = new TerritoryReference() { continentID = 2, territoryID = 5 };
      territories[4].neighbors[1] = new TerritoryReference() { continentID = 2, territoryID = 7 };

      territories[5].name = "Kamchatka";
      territories[5].position = new Vector2(638, 73);
      territories[5].neighbors = new TerritoryReference[5];
      territories[5].neighbors[0] = new TerritoryReference() { continentID = 2, territoryID = 3 };
      territories[5].neighbors[1] = new TerritoryReference() { continentID = 2, territoryID = 4 };
      territories[5].neighbors[2] = new TerritoryReference() { continentID = 2, territoryID = 7 };
      territories[5].neighbors[3] = new TerritoryReference() { continentID = 2, territoryID = 11 };
      territories[5].neighbors[4] = new TerritoryReference() { continentID = 4, territoryID = 0 }; // Alaska

      territories[6].name = "Medio Oriente";
      territories[6].position = new Vector2(506, 266);
      territories[6].neighbors = new TerritoryReference[6];
      territories[6].neighbors[0] = new TerritoryReference() { continentID = 2, territoryID = 0 };
      territories[6].neighbors[1] = new TerritoryReference() { continentID = 2, territoryID = 1 };
      territories[6].neighbors[2] = new TerritoryReference() { continentID = 2, territoryID = 2 };
      territories[6].neighbors[3] = new TerritoryReference() { continentID = 0, territoryID = 4 }; // Europa Meridionale
      territories[6].neighbors[4] = new TerritoryReference() { continentID = 0, territoryID = 5 }; // Ucraina
      territories[6].neighbors[5] = new TerritoryReference() { continentID = 1, territoryID = 2 }; // Egitto

      territories[7].name = "Mongolia";
      territories[7].position = new Vector2(633, 145);
      territories[7].neighbors = new TerritoryReference[5];
      territories[7].neighbors[0] = new TerritoryReference() { continentID = 2, territoryID = 1 };
      territories[7].neighbors[1] = new TerritoryReference() { continentID = 2, territoryID = 3 };
      territories[7].neighbors[2] = new TerritoryReference() { continentID = 2, territoryID = 4 };
      territories[7].neighbors[3] = new TerritoryReference() { continentID = 2, territoryID = 5 };
      territories[7].neighbors[4] = new TerritoryReference() { continentID = 2, territoryID = 9 };

      territories[8].name = "Siam";
      territories[8].position = new Vector2(661, 255);
      territories[8].neighbors = new TerritoryReference[3];
      territories[8].neighbors[0] = new TerritoryReference() { continentID = 2, territoryID = 1 };
      territories[8].neighbors[1] = new TerritoryReference() { continentID = 2, territoryID = 2 };
      territories[8].neighbors[2] = new TerritoryReference() { continentID = 3, territoryID = 1 }; // Indonesia

      territories[9].name = "Siberia";
      territories[9].position = new Vector2(542, 105);
      territories[9].neighbors = new TerritoryReference[5];
      territories[9].neighbors[0] = new TerritoryReference() { continentID = 2, territoryID = 1 };
      territories[9].neighbors[1] = new TerritoryReference() { continentID = 2, territoryID = 3 };
      territories[9].neighbors[2] = new TerritoryReference() { continentID = 2, territoryID = 7 };
      territories[9].neighbors[3] = new TerritoryReference() { continentID = 2, territoryID = 10 };
      territories[9].neighbors[4] = new TerritoryReference() { continentID = 2, territoryID = 11 };

      territories[10].name = "Urali";
      territories[10].position = new Vector2(501, 135);
      territories[10].neighbors = new TerritoryReference[4];
      territories[10].neighbors[0] = new TerritoryReference() { continentID = 2, territoryID = 0 };
      territories[10].neighbors[1] = new TerritoryReference() { continentID = 2, territoryID = 1 };
      territories[10].neighbors[2] = new TerritoryReference() { continentID = 2, territoryID = 9 };
      territories[10].neighbors[3] = new TerritoryReference() { continentID = 0, territoryID = 5 }; // Ucraina


      territories[11].name = "Jacuzia";
      territories[11].position = new Vector2(586, 59);
      territories[11].neighbors = new TerritoryReference[3];
      territories[11].neighbors[0] = new TerritoryReference() { continentID = 2, territoryID = 3 };
      territories[11].neighbors[1] = new TerritoryReference() { continentID = 2, territoryID = 5 };
      territories[11].neighbors[2] = new TerritoryReference() { continentID = 2, territoryID = 9 };

      asia.territories = territories;
      // Aggiunge il continente allo stato
      board.continents[2] = asia;

      // Australia = 3
      // Creazione continente
      Continent australia = new Continent() { name = "Australia", reinforcements = 2 };
      // Creazione territori
      territories = new Territory[4];
      for (int i = 0; i < territories.Count(); ++i)
      {
        territories[i].territoryID = i;
        territories[i].hasOwner = false;
        territories[i].continentID = 3;
      }

      territories[0].name = "Australia Orientale";
      territories[0].position = new Vector2(746, 432);
      territories[0].neighbors = new TerritoryReference[2];
      territories[0].neighbors[0] = new TerritoryReference() { continentID = 3, territoryID = 2 };
      territories[0].neighbors[1] = new TerritoryReference() { continentID = 3, territoryID = 3 };

      territories[1].name = "Indonesia";
      territories[1].position = new Vector2(700, 320);
      territories[1].neighbors = new TerritoryReference[3];
      territories[1].neighbors[0] = new TerritoryReference() { continentID = 3, territoryID = 2 };
      territories[1].neighbors[1] = new TerritoryReference() { continentID = 3, territoryID = 3 };
      territories[1].neighbors[2] = new TerritoryReference() { continentID = 2, territoryID = 8 }; // Siam
      
      territories[2].name = "Nuova Guinea";
      territories[2].position = new Vector2(770, 345);
      territories[2].neighbors = new TerritoryReference[3];
      territories[2].neighbors[0] = new TerritoryReference() { continentID = 3, territoryID = 0 };
      territories[2].neighbors[1] = new TerritoryReference() { continentID = 3, territoryID = 1 };
      territories[2].neighbors[2] = new TerritoryReference() { continentID = 3, territoryID = 3 };

      territories[3].name = "Australia Occidentale";
      territories[3].position = new Vector2(690, 400);
      territories[3].neighbors = new TerritoryReference[3];
      territories[3].neighbors[0] = new TerritoryReference() { continentID = 3, territoryID = 0 };
      territories[3].neighbors[1] = new TerritoryReference() { continentID = 3, territoryID = 1 };
      territories[3].neighbors[2] = new TerritoryReference() { continentID = 3, territoryID = 2 }; // Siam

      australia.territories = territories;
      // Aggiunge il continente allo stato
      board.continents[3] = australia;

      // America del Nord = 4
      // Creazione continente
      Continent nordAmerica = new Continent() { name = "America del Nord", reinforcements = 5 };
      // Creazione territori
      territories = new Territory[9];
      for (int i = 0; i < territories.Count(); ++i)
      {
        territories[i].territoryID = i;
        territories[i].hasOwner = false;
        territories[i].continentID = 4;
      }

      territories[0].name = "Alaska";
      territories[0].position = new Vector2(85, 59);
      territories[0].neighbors = new TerritoryReference[3];
      territories[0].neighbors[0] = new TerritoryReference() { continentID = 4, territoryID = 1 }; // Alberta
      territories[0].neighbors[1] = new TerritoryReference() { continentID = 4, territoryID = 5 }; // Territori del Nord Ovest
      territories[0].neighbors[2] = new TerritoryReference() { continentID = 2, territoryID = 5 }; // Kamchatka

      territories[1].name = "Alberta";
      territories[1].position = new Vector2(102, 120);
      territories[1].neighbors = new TerritoryReference[4];
      territories[1].neighbors[0] = new TerritoryReference() { continentID = 4, territoryID = 0 }; // Alaska
      territories[1].neighbors[1] = new TerritoryReference() { continentID = 4, territoryID = 6 };
      territories[1].neighbors[2] = new TerritoryReference() { continentID = 4, territoryID = 7 }; 
      territories[1].neighbors[3] = new TerritoryReference() { continentID = 4, territoryID = 8 };

      territories[2].name = "America Centrale";
      territories[2].position = new Vector2(60, 206);
      territories[2].neighbors = new TerritoryReference[3];
      territories[2].neighbors[0] = new TerritoryReference() { continentID = 4, territoryID = 3 };
      territories[2].neighbors[1] = new TerritoryReference() { continentID = 4, territoryID = 8 };
      territories[2].neighbors[2] = new TerritoryReference() { continentID = 5, territoryID = 3 }; // Venezuela

      territories[3].name = "Stati Uniti Occidentali";
      territories[3].position = new Vector2(126, 195);
      territories[3].neighbors = new TerritoryReference[4];
      territories[3].neighbors[0] = new TerritoryReference() { continentID = 4, territoryID = 2 };
      territories[3].neighbors[1] = new TerritoryReference() { continentID = 4, territoryID = 6 };
      territories[3].neighbors[2] = new TerritoryReference() { continentID = 4, territoryID = 7 }; 
      territories[3].neighbors[3] = new TerritoryReference() { continentID = 4, territoryID = 8 };

      territories[4].name = "Groenlandia";
      territories[4].position = new Vector2(249, 68);
      territories[4].neighbors = new TerritoryReference[4];
      territories[4].neighbors[0] = new TerritoryReference() { continentID = 4, territoryID = 5 };
      territories[4].neighbors[1] = new TerritoryReference() { continentID = 4, territoryID = 6 };
      territories[4].neighbors[2] = new TerritoryReference() { continentID = 4, territoryID = 7 };
      territories[4].neighbors[3] = new TerritoryReference() { continentID = 0, territoryID = 1 }; // Islanda

      territories[5].name = "Territori del Nord Ovest";
      territories[5].position = new Vector2(130, 71);
      territories[5].neighbors = new TerritoryReference[5];
      territories[5].neighbors[0] = new TerritoryReference() { continentID = 4, territoryID = 0 };
      territories[5].neighbors[1] = new TerritoryReference() { continentID = 4, territoryID = 1 };
      territories[5].neighbors[2] = new TerritoryReference() { continentID = 4, territoryID = 4 };
      territories[5].neighbors[3] = new TerritoryReference() { continentID = 4, territoryID = 6 };
      territories[5].neighbors[4] = new TerritoryReference() { continentID = 4, territoryID = 7 };

      territories[6].name = "Ontario";
      territories[6].position = new Vector2(161, 144);
      territories[6].neighbors = new TerritoryReference[6];
      territories[6].neighbors[0] = new TerritoryReference() { continentID = 4, territoryID = 1 };
      territories[6].neighbors[1] = new TerritoryReference() { continentID = 4, territoryID = 3 };
      territories[6].neighbors[2] = new TerritoryReference() { continentID = 4, territoryID = 4 };
      territories[6].neighbors[3] = new TerritoryReference() { continentID = 4, territoryID = 5 };
      territories[6].neighbors[4] = new TerritoryReference() { continentID = 4, territoryID = 7 };
      territories[6].neighbors[5] = new TerritoryReference() { continentID = 4, territoryID = 8 };

      territories[7].name = "Quebec";
      territories[7].position = new Vector2(220, 154);
      territories[7].neighbors = new TerritoryReference[3];
      territories[7].neighbors[0] = new TerritoryReference() { continentID = 4, territoryID = 3 };
      territories[7].neighbors[1] = new TerritoryReference() { continentID = 4, territoryID = 4 };
      territories[7].neighbors[2] = new TerritoryReference() { continentID = 4, territoryID = 7 };

      territories[8].name = "Stati Uniti Occidentali";
      territories[8].position = new Vector2(73, 158);
      territories[8].neighbors = new TerritoryReference[4];
      territories[8].neighbors[0] = new TerritoryReference() { continentID = 4, territoryID = 1 };
      territories[8].neighbors[1] = new TerritoryReference() { continentID = 4, territoryID = 2 };
      territories[8].neighbors[2] = new TerritoryReference() { continentID = 4, territoryID = 3 };
      territories[8].neighbors[3] = new TerritoryReference() { continentID = 4, territoryID = 6 };

      nordAmerica.territories = territories;
      // Aggiunge il continente allo stato
      board.continents[4] = nordAmerica;

      // America del Sud = 5
      // Creazione continente
      Continent sudAmerica = new Continent() { name = "America del Sud", reinforcements = 2 };
      // Creazione territori
      territories = new Territory[4];
      for (int i = 0; i < territories.Count(); ++i)
      {
        territories[i].territoryID = i;
        territories[i].hasOwner = false;
        territories[i].continentID = 5;
      }

      territories[0].name = "Argentina";
      territories[0].position = new Vector2(91, 400);
      territories[0].neighbors = new TerritoryReference[2];
      territories[0].neighbors[0] = new TerritoryReference() { continentID = 5, territoryID = 1 };
      territories[0].neighbors[1] = new TerritoryReference() { continentID = 5, territoryID = 2 };

      territories[1].name = "Brasile";
      territories[1].position = new Vector2(146, 325);
      territories[1].neighbors = new TerritoryReference[4];
      territories[1].neighbors[0] = new TerritoryReference() { continentID = 5, territoryID = 0 };
      territories[1].neighbors[1] = new TerritoryReference() { continentID = 5, territoryID = 1 };
      territories[1].neighbors[2] = new TerritoryReference() { continentID = 5, territoryID = 3 };
      territories[1].neighbors[3] = new TerritoryReference() { continentID = 1, territoryID = 4 }; // Africa Del Nord

      territories[2].name = "Peru";
      territories[2].position = new Vector2(69, 347);
      territories[2].neighbors = new TerritoryReference[3];
      territories[2].neighbors[0] = new TerritoryReference() { continentID = 5, territoryID = 0 };
      territories[2].neighbors[1] = new TerritoryReference() { continentID = 5, territoryID = 1 };
      territories[2].neighbors[2] = new TerritoryReference() { continentID = 5, territoryID = 3 };
      
      territories[3].name = "Venezuela";
      territories[3].position = new Vector2(112, 266);
      territories[3].neighbors = new TerritoryReference[3];
      territories[3].neighbors[0] = new TerritoryReference() { continentID = 5, territoryID = 0 };
      territories[3].neighbors[1] = new TerritoryReference() { continentID = 5, territoryID = 1 };
      territories[3].neighbors[2] = new TerritoryReference() { continentID = 4, territoryID = 3 }; // America Centrale

      sudAmerica.territories = territories;
      // Aggiunge il continente allo stato
      board.continents[5] = sudAmerica;


      

      // Normalizza le posizioni su una risoluzione di 800x480
      //for (int i = 0; i < board.continents.Count(); ++i)
      //{
      //  for (int j = 0; j < board.continents[i].territories.Count(); ++j)
      //  {
      //    board.continents[i].territories[j].position.X /= 1000.0f;
      //    board.continents[i].territories[j].position.X *= 800.0f;
      //    board.continents[i].territories[j].position.Y /= 500;
      //    board.continents[i].territories[j].position.Y *= 480;
      //  }
      //}

      return board;
    }


    public void GenerateDeck()
    {
      // Genera le carte
      deck = new Deck() { cards = new List<Card>(42) };
      board.IterTerritories(t =>
      {
        deck.cards.Add(new Card() { type = CardType.Artillery, territory = t });
      });

      // Tipi
      for (int i = 0; i < 42; i++)
      {
        if (i > 13) deck.cards[i] = new Card() { type = CardType.Cavalry, territory = deck.cards[i].territory };
        if (i > 27) deck.cards[i] = new Card() { type = CardType.Infantry, territory = deck.cards[i].territory };

      }

      deck.cards.Add(new Card() { type = CardType.Jolly, territory = new Territory() });
      deck.cards.Add(new Card() { type = CardType.Jolly, territory = new Territory() });
    }


  }

}
